<{include file="Public/top.html" }>
</head>
<body>
<div id="warpper">
    <div class="content">
        <div class="location">定时抽奖</div>
        <{include file="./timingNav.html" }>
        <div class="filedSet" style="padding-bottom: 0;">
            <div class="search">
                <form action="" method="get" id="searchForm" class="ui-form reportForm">
                    <input name="m" type="hidden" value="<{$module}>">
                    <input name="c" type="hidden" value="<{$controller}>">
                    <input name="a" type="hidden" value="<{$action}>">

                    <input name="p" id="page" type="hidden" value="<{$page|default:1}>">
                    <input name="limit" id="limit" type="hidden" value="<{$limit|default:10}>">
                    <!--<input name="ofield" id="ofield" type="hidden" value="<{$ofield}>">-->
                    <!--<input name="otype"  id="otype"  type="hidden" value="<{$otype}>">-->


                    <div class="ui-form-item inline-block">
                        <label class="ui-label">关键字</label>
                        <input type="text" name="title" class="ui-text bg-text keyword" placeholder="活动名" value="<{$title}>" />
                    </div>
                    <div class="ui-form-item inline-block">
                        <button type="submit" class="ui-button" onclick="LayerShow();">查询</button>
                    </div>
                </form>
            </div>
        </div>

        <!--表格内容-->
        <div class="mainGrid">
            <table class="ui-table ui-body">
                <thead>
                <tr>
                    <th class="pct20">活动名</th>
                    <th class="pct10">会员等级</th>
                    <th class="pct10">积分</th>
                    <th class="pct10">原价</th>
                    <{if $action eq timingPrepare}>
                    <th class="pct20">显示开始时间</th>
                    <{else}>
                    <th class="pct20">显示结束时间</th>
                    <{/if}>
                    <th class="pct10">奖品数量</th>
                    <{if $action neq 'timingPrepare'}>
                    <th class="pct10">参与人数</th>
                    <th class="pct10">参与次数</th>
                    <{/if}>
                    <th class="pct20 last-col">操作</th>
                </tr>
                </thead>
                <tbody>
                <{foreach from=$list item=item}>
                <tr>
                    <td class="title" data="<{$item.listPic}>"><{$item.title}></td>
                    <td><{$item.userLevelRequire|default:0}></td>
                    <td><{$item.points|default:0}></td>
                    <td><{$item.originalPrice}></td>
                    <{if $action eq timingPrepare}>
                    <td><{$item.beginShowTimestamp|date_format:'%Y-%m-%d %T'}></td>
                    <{else}>
                    <td><{$item.endTime|date_format:'%Y-%m-%d %T'}></td>
                    <{/if}>
                    <td><{$item.prizeNum}></td>
                    <{if $action neq 'timingPrepare'}>
                    <td><{$item.joinPeople}></td>
                    <td><{$item.joinTimes}></td>
                    <{/if}>

                    <td class="ta_l">
                        <div class="handler">
                            <{$action}>
                            <{if $action neq 'timingPrepare'}>
                            <a href="<{u('timingMember?id='|cat:$item.id)}>" onclick="LayerShow();">查看记录</a>
                            <span class="sep">|</span>
                            <{if $action eq 'timingOnline'}>
                            <a href="javascript:writeNameList('<{$item.id}>')">中奖名单</a>
                            <span class="sep">|</span>
                            <{/if}>
                            <{if $action eq 'timingFinish'}>
                            <a href="<{U('timingMember')}>&id=<{$item.id}>&result=2">中奖名单</a>
                            <{/if}>
                            <{/if}>
                            <{if $action neq 'timingFinish'}>
                            <a href="<{u('timingEdit?id='|cat:$item.id)}>" onclick="LayerShow();">修改</a>
                            <{/if}>
                            <{if $action neq 'timingOnline'}>
                            <span class="sep">|</span>
                            <a href="<{u('timingDel?id='|cat:$item.id)}>" onclick="javascript:return del()">删除</a>
                            <{/if}>
                        </div>
                    </td>
                </tr>
                <{/foreach}>
                </tbody>
            </table>
        </div>
        <div class="pagination">
            <!--描述：分页-->
            <{include file="Public/page.html" }>
        </div>
    </div>
</div>
<div id="praise" style="display:none;">
    <form id="nameList">
        <table class="praise_tab" width="100%">
            <{include file="PointLottery/writeNameList.html"}>
        </table>
    </form>
</div>
<{include file="Public/foot.html" }>
</body>
</html>
<script>
    $(document).ready(
            $('.title').on('mouseover',function (e) {
                if(e.target.tagName!='TD'){
                    return;
                }
                layer.closeAll();
                var url=$(e.target).attr('data');
                var title = e.target.innerText;
                layer.tips("<h1 style='color: #000000;text-overflow:ellipsis;overflow: hidden;display: -webkit-box;-webkit-line-clamp: 1;-webkit-box-orient: vertical;min-height: 25px;'>"+title+'</h1><img src="'+url+'" style="width:280px;height:140px;">', e.target,
                        {
                            tips:[4,'#ffffff'],
                            area: ['300px', '180px'],
                            skin:'BoxShadow'
                        });

            })
    );
    function del(){
        if(confirm("确认删除吗？")){
            return true;
        }else{
            return false;
        }
    }
    function writeNameList(id){
        $.getJSON("<{U('getNameList')}>",{id:id},function(data){
            $(".praise_tab").empty();
            $(".praise_tab").append(data);
        });
        var praise = dialog({
            title: '中奖名单录入(名单未填满无效)',
            width: 410,
            content:$("#praise"),
            onshow: function(){
                $("#praise form")[0].reset();
            },
            button: [
                {
                    value: '确认',
                    callback: function () {
                        var num = $('input:text').length-2;
                        for (var i=0;i<num;i++) {
                            if($('#realName'+i).val()==''){
                                $('#realName'+i).css("border","2px solid #fe7f30");
                                layer.msg("请填写完整信息");
                                return false;
                            }else{
                                $('#realName'+i).css("border","1px solid #e5e5e5");
                            }
                            if($('#bindPhone'+i).val()==''){
                                $('#bindPhone'+i).css("border","2px solid #fe7f30");
                                layer.msg("请填写完整信息");
                                return false;
                            }else if($('#bindPhone'+i).val().length <11){
                                $('#bindPhone'+i).css("border","2px solid #fe7f30");
                                layer.msg("手机号码填写有误");
                                return false;
                            }else{
                                $('#bindPhone'+i).css("border","1px solid ##fe7f30");
                            }
                        }
                        $.ajax({
                            type:"get",
                            url:"<{U('writeWinList')}>&id="+id,
                            dataType: 'json',
                            data: $('#nameList').serialize(),
                            success: function(data){
                                if(data.status==1){
                                    layer.msg("第"+data.id+"条"+data.msg);
                                } else {
//                                    console.log(data.id);
                                    if(data.id) {
                                        alert("第"+data.id+"条"+data.tip);
                                    }
                                    layer.msg(data.msg);
                                }

                            }
                        });


                    },
                    autofocus: true
                },
            ],
        });
        praise.showModal();
    }
</script>